<template>
    <div class="bx-editor">
        <van-nav-bar
                title="确认信息"
                left-text="返回"
                left-arrow
                border
                fixed
                @click-left="$router.go(-1)"
        />
        <div style="height:50px"></div>
        <div class="title">
            确认信息
        </div>
        <div>
            <van-cell-group>
                <van-field v-model="order_no" label="投保单号" placeholder="请填写投保单号" size="large" required />

                <van-field readonly clickable required label="保险公司选择" :value="companyName" placeholder="--请选择--" @click="companyPickerShow = true" />
                <van-popup v-model="companyPickerShow" position="bottom">
                    <van-picker show-toolbar :columns="companySource" :default-index="companyIndex" value-key="name" @cancel="companyPickerShow = false" @confirm="oncompany" />
                </van-popup>

                <van-field readonly clickable required label="投保险种选择" :value="goodsName" placeholder="--请选择--" @click="goodsPickerShow = true" />
                <van-popup v-model="goodsPickerShow" position="bottom">
                    <van-picker show-toolbar :columns="goodsSource" :default-index="goodsIndex" value-key="name" @cancel="goodsPickerShow = false" @confirm="onClient" />
                </van-popup>

                <div class="radio">
                    <div><span style="color: #ee0a24">*</span>本月是否开票</div>
                    <van-radio-group v-model="invoice_pay">
                        <van-radio :name="1" checked-color="#366cb3">是</van-radio>
                        <van-radio :name="0" checked-color="#366cb3">否</van-radio>
                    </van-radio-group>
                </div>
            </van-cell-group>
        </div>

        <div class="foot-btn">
            <div class="blue-btn" @click="pushInfo">保存</div>
            <!-- <div class="red-btn">取消</div> -->
        </div>
    </div>
</template>
<script>
export default {
    name: "kfconfirmInsurance",
    data() {
        return {
            is: false,
            order_no: '', // 订单号
            companyIndex: 0, //所属行业
            companyName: '', //所属行业
            companyPickerShow: false,
            companySource: [],


            goodsIndex: 0,
            goodsName: '',
            goodsPickerShow: false,
            goodsSource: [], //客户类型


            invoice_pay: 0, //是否产生佣金

        };
    },
    methods: {

        // 所属行业
        onClient(value, index) {
            this.goodsIndex = index;
            this.goodsName = value.name
            this.goodsPickerShow = false;
        },
        // 合作客户类型
        oncompany(value, index) {
            this.companyIndex = index;
            this.companyName = value.name
            this.companyPickerShow = false;
        },
        // 方法
        getInfo() {
            let params = {
                wx_member_id: localStorage.getItem('wx_member_id'),
                token: localStorage.getItem('token'),
                id: this.$route.query.oId,

            };
            this.$post("/api/order_detail/confirm_order", params)
                .then(res => {
                    if (res.code == 1) {
                        this.companySource = res.data.company
                        this.goodsSource = res.data.goods
                    } else {
                        this.Toast(res.msg)
                    }
                })
                .catch(err => { });
        },
        pushInfo() {
            if (this.order_no == '') {
                this.$Toast('请填写投保单号');
                return;
            }
            if (this.companyName == '') {
                this.$Toast('请选择保险公司');
                return;
            }
            if (this.goodsName == '') {
                this.$Toast('请选择投保选种');
                return;
            }

            let params = {
                wx_member_id: localStorage.getItem('wx_member_id'),
                token: localStorage.getItem('token'),
                id: this.$route.query.oId,
                company_id: this.companySource[this.companyIndex].id,
                insurance_name: this.goodsName,
                order_no: this.order_no,
                is_invoice: this.invoice_pay,

            };
            this.$post("/api/order_detail/save_confirm_order", params)
                .then(res => {
                    if (res.code == 1) {
                        this.$Toast(res.msg)
                        setTimeout(() => {
                            this.$router.go(-1)
                        }, 1500);
                    } else {
                        this.Toast(res.msg)
                    }
                })
                .catch(err => { });
        }
    },
    beforeCreate() {
        // document.querySelector("body").setAttribute("style", "background-color:#fff");
    },
    created() {
        // 实例创建完成
        this.getInfo();
    },
};
</script>
<style lang="less" scoped>
// @import url("../../asset/css/kfconfirmInsurance");
.radio {
    display: flex;
    align-items: center;
    padding: 10px 9px;

    > div:nth-of-type(1) {
        width: 116px;
        font-size: 13px;
        color: #323233;
    }

    > div:nth-of-type(2) {
        font-size: 12px;
    }
}

.foot-btn {
    padding-bottom: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>